fix: last activity timestamp shows incorrectly for all projects#482
Open
uddhav05-cyber wants to merge 3 commits into
Open
fix: last activity timestamp shows incorrectly for all projects#482uddhav05-cyber wants to merge 3 commits into
uddhav05-cyber wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect/stale “Last Activity” relative timestamps by moving dayjs.extend(relativeTime) out of the RepositoryItem component and extracting the logic into a reusable useLastModified hook.
Changes:
- Added
hooks/useLastModified.tsxcustom hook and initializeddayjsrelative-time plugin at module scope. - Updated
components/RepositoryItem.tsxto consumeuseLastModifiedand removed inlinedayjs/hook logic.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| hooks/useLastModified.tsx | New hook for computing “last modified” relative time; initializes dayjs plugin once. |
| components/RepositoryItem.tsx | Uses the new hook instead of defining it inline; removes repeated dayjs.extend. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+3
to
+16
| import { useEffect, useState } from "react"; | ||
|
|
||
| // Extend dayjs with relativeTime plugin at module scope | ||
| dayjs.extend(relativeTime); | ||
|
|
||
| export const useLastModified = (date: string) => { | ||
| const [lastModified, setLastModified] = useState(""); | ||
|
|
||
| useEffect(() => { | ||
| // eslint-disable-next-line react-hooks/set-state-in-effect | ||
| setLastModified(dayjs(date).fromNow()); | ||
| }, [date]); | ||
|
|
||
| return lastModified; |
Comment on lines
20
to
+29
| useEffect(() => { | ||
| if (isIssueOpen) { | ||
| // eslint-disable-next-line react-hooks/set-state-in-effect | ||
| setIsIssuesListVisible(true); | ||
| } else { | ||
| // Delay unmounting to allow close animation to complete | ||
| const timer = setTimeout(() => setIsIssuesListVisible(false), 300); | ||
| const timer = setTimeout(() => { | ||
| // eslint-disable-next-line react-hooks/set-state-in-effect | ||
| setIsIssuesListVisible(false); | ||
| }, 300); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #440
Problem
dayjs.extend(relativeTime)was being called inside the component on every render, causing all repositories to display an incorrect/stale relative timestamp.Fix
useLastModifiedinto a proper custom hook inhooks/useLastModified.tsxdayjs.extend(relativeTime)now runs once at module scopeRepositoryItem.tsximports and uses the new hook cleanlyChanges
hooks/useLastModified.tsx— new custom hookcomponents/RepositoryItem.tsx— removed inline dayjs.extend, uses new hookNote: PR #442 addressed the same issue but has been unreviewed for several months.